package by.gravity.billprinter.task;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

public abstract class ProgressAsyncTask extends AsyncTask<Void, String, String> {

	private ProgressDialog dialog;

	private boolean showProgress;

	public ProgressAsyncTask(Context context, boolean showProgress) {

		dialog = new ProgressDialog(context);
		dialog.setCancelable(false);
		this.showProgress = showProgress;
	}

	private void setMessage(String message) {

		dialog.setMessage(message);
	}

	@Override
	protected void onProgressUpdate(String... values) {

		super.onProgressUpdate(values);
		setMessage(values[0]);
	}

	@Override
	protected void onPreExecute() {

		super.onPreExecute();
		if (showProgress) {
			dialog.show();
		}
	}

	@Override
	protected void onPostExecute(String result) {

		super.onPostExecute(result);
		if (showProgress) {
			dialog.hide();
		}
	}

}
